<?php echo $this->headScript();?>
<?php echo $this->headLink();?>
<script>
function checkLogin(){
    $.ajax({
        url: '/resume/check-login',
        success: function(result){
            if(!result) document.location.href = '/user/login';
        }
   });
}
</script>
<form id="frmsearch" action="/company" method="post">
<div class="block-search">
	<label>Search</label>
	<input name="txtSearch" id="txtSearch" type="text" value="<?php echo $this->txtSearch; ?>"/>
	<select name="opt">
		<option value="company_name" <?php echo ($this->opt == 'company_name')?"selected":''?>>Company name</option>
		<option value="assign_cons" <?php echo ($this->opt == 'assign_cons')?"selected":''?>>Consultant</option>
        <option value="busines_type" <?php echo ($this->opt == 'busines_type')?"selected":''?>>Business type</option>
	</select>
    <input class="button01" name="btSearch" type="submit" value="Search"/>
</div>
<div style="height:20px"> </div>
<div>	
	<div style="width:300px;float:left">
	<a href="/company/add-company" style="text-decoration:none;">
		<input class="button01" type="button" value="Add Company" />
	</a>
	<input class="button01 delete" type="button" value="Delete" />
	</div>
  	<div style="width:310px;float:right">          
	    <label for="choice">Sort : </label>
	    <select name="sort" id="sort" style="width:120px">
	        <option value="created_date" <?php if ($this->sort=="created_date") echo "selected";?>>Created Date</option>
            <option value="company_name" <?php if ($this->sort=="company_name") echo "selected";?>>Name</option>
	    </select>
	    <select name="order" id="order" style="width:80px">
	    	<option value="DESC" <?php if ($this->order=="DESC") echo "selected";?>>DESC</option>
            <option value="ASC" <?php if ($this->order=="ASC") echo "selected";?>>ASC</option>
	    </select>
	    <input type="submit" class="button01" value="Sort" />
    </div>
</div>
</form>
<div style="clear:both;">&nbsp;</div>
<p class="today-entry" id="report">&nbsp;</p>
<!-- list company -->
<div id="box">   
	<?php echo $this->partial('company/list-company.phtml', array('paginator' => $this->paginator)); ?>
</div>
<!-- end list company -->
<div style="clear:both">&nbsp;</div>

<!-- pagging -->
<div class="footer clearfix">
<?php if(count($this->paginator)) :?>
    <?php echo $this->paginationControl($this->paginator, 'Sliding', 'company/pagination.phtml'); ?>
<?php endif;?>
</div>
<!-- end pagging -->

<!-- view poup -->
<div id="view_company" style="width:600px;height: 350px; overflow-y:scroll; display: none;">&nbsp;</div>
<?php echo $this->partial ( '/company/comment.phtml' )?> 
<div id="allcomment" style="width:500px;height:200px; overflow-y:scroll; display: none;">&nbsp;</div>
<!-- end view popup -->

<script language="javascript">
$(document).ready(function() {
     //Begin View detail candidate
     $(".view_company").fancybox();
     $(".view_company").click(function(){
         checkLogin();
         $('#view_company').html('');
         var company_id = $(this).attr('id');
         $.ajax({
             url: '/company/view-company',
             type: "POST",
             data: { 
            	 company_id: company_id, 
             },
             success: function(result) {
                 $('#view_company').html(result);
             }
         });
     });
     //End View detail candidate
 });

$(document).ready(function() {
	//report company
	$.ajax({
  	  	url: '/company/company-report',
  	  	success: function(result) {
  	    	$('#report').html(result);
  	  	}
  	});

    //Begin Comment for resume
    $(".addcomment").fancybox();
    $(".addcomment").click(function(){
        $('#contentcomment').val(''); 
        $('input[name=company_id]').val($(this).attr('id'));
    });

    $("#insertcomment").click(function(){
        checkLogin();
        if(!$('#contentcomment').val()) {
            $('#msgcomment').html('Content is not null'); 
            return;
        }
        var company_id = $('input[name=company_id]').val();
        $.ajax({
            url: '/company/save-comment',
            type: "POST",
            data: { 
            	company_id: company_id, 
                consultant_id: $('input[name=consultant_id]').val(), 
                content: $('#contentcomment').val()
            },
            success: function(result) {
                $('#viewcomment' + company_id).html(result);
                $.fancybox.close();
            }
        });
    });

    $(".deletecomment").click(function(){
        alert(222);
    	//$this.parent().hidden();
    });
    

    $(".allcomment").fancybox();
    $(".allcomment").click(function(){
        checkLogin();
        var company_id = $(this).attr('id');
        $.ajax({
            url: '/company/all-comment',
            type: "POST",
            data: { 
            	company_id: company_id, 
            },
            success: function(result) {
                $('#allcomment').html(result);
            }
        });
    });
	
	$('.delete').click(function(){
        if($('input[name="company_chk[]"]').is(':checked')) {
            var answer = confirm('Are you sure you want to delete');
            if (answer) {
            	var listCompany = '';
                var checkboxes = $('input[name="company_chk[]"]:checkbox:checked');
                checkboxes.each(function() {
                	if(listCompany) listCompany = listCompany + ',' + $(this).val();
                	else listCompany = $(this).val();
                });
            	$.ajax({
              	  	url: '/company/delete-company',
                	type: "POST",
        			data: { 
                       listid: listCompany
                    },
              	  	success: function(result) {
                  	  	$('#box').html(result);
              	  	}
              	});
            }
        } else {
            alert('Please select company to delete');
            return false;
        }
  	});  
});
    //End Comment for resume
</script>